const { app, BrowserWindow } = require("electron")
const WinState = require("electron-win-state").default // 窗口状态
const path = require("path")
//获取网站的截图
require('./controller/getSource')
//alert
require('./controller/alert')
//打开新的窗口
require('./controller/openNewWindow')
//获取图片列表
require('./controller/getFileList')
//获取菜单
require('./controller/buildMenu')
//托盘
const createTray = require('./tray')

const createWindow = () => {
  const winState = new WinState({
    defaultWidth: 1000,
    defaultHeight: 800,
    electronStoreOptions:{name:'window'}
  })
  const win = new BrowserWindow({
    //自定义窗口的状态
    ...winState.winOptions,
    webPreferences:{
      //定义预加载的js
      preload:path.resolve(__dirname,'./preload')
    },
    show:false // 不显示窗口
  })

  win.loadURL("http://localhost:5173") 

  //win.webContents.openDevTools() //打开调试

  winState.manage(win) // 窗口状态管理

  win.on("ready-to-show",()=>{
    win.show()
  })
  createTray(app,win)
}

app.whenReady().then(() => {
  createWindow()
  app.on("activate", () => {
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
  })

})
app.on("window-all-closed", () => {
  if (process.platform !== "darwin") app.quit()
})